Added DevController.configuration and configurations methods. These parse the
authoremellor@ewan <emellor@ewan>
Fri, 30 Sep 2005 09:48:49 +0000 (10:48 +0100)
committeremellor@ewan <emellor@ewan>
Fri, 30 Sep 2005 09:48:49 +0000 (10:48 +0100)
store for the current device configuration, and convert it back into the
s-expression used in the config files and the save files.  This means that we
can bring the devices up properly on restore.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xend/server/DevController.py
tools/python/xen/xend/server/blkif.py
tools/python/xen/xend/server/netif.py

index 0130075ac359ab9bdaa68487cacb3376fdf58856..942efd46b4d245175af256c5f8f56ee8b31deb0f 100644 (file)
@@ -75,12 +75,28 @@ class DevController:
         """
 
         frontpath = self.frontendPath(devid)
-        backpath = xstransact.Read("%s/backend" % frontpath)
+        backpath = xstransact.Read(frontpath, "backend")
 
         xstransact.Remove(frontpath)
         xstransact.Remove(backpath)
 
 
+    def configurations(self):
+        return map(lambda x: self.configuration(int(x)),
+                   xstransact.List(self.frontendRoot()))
+
+
+    def configuration(self, devid):
+        """@return an s-expression giving the current configuration of the
+        specified device.  This would be suitable for giving to {@link
+        #createDevice} in order to recreate that device."""
+
+        backdomid = int(xstransact.Read(self.frontendPath(devid),
+                                        "backend-id"))
+
+        return [self.deviceClass, ['backend', backdomid]]
+
+
     def sxprs(self):
         """@return an s-expression describing all the devices of this
         controller's device-class.
@@ -150,6 +166,12 @@ class DevController:
                 raise
 
 
+    def readBackend(self, devid, *args):
+        frontpath = self.frontendPath(devid)
+        backpath = xstransact.Read(frontpath, "backend")
+        return xstransact.Read(backpath, *args)
+
+
     ## private:
 
     def writeDetails(self, config, devid, backDetails, frontDetails):
@@ -211,4 +233,5 @@ class DevController:
 
 
     def frontendMiscPath(self):
-        return "%s/device-misc/%s" % (self.vm.getPath(), self.deviceClass)
+        return "%s/device-misc/%s" % (self.vm.getPath(),
+                                      self.deviceClass)
index 51ca12b131a8510303215fbededb805d510365ec..bfc559f74f9eb3452a03d87ed1ee04a14e0aa467 100755 (executable)
@@ -40,14 +40,15 @@ class BlkifController(DevController):
     def getDeviceDetails(self, config):
         """@see DevController.getDeviceDetails"""
         
-        typedev = sxp.child_value(config, 'dev')
-        if re.match('^ioemu:', typedev):
+        dev = sxp.child_value(config, 'dev')
+        if re.match('^ioemu:', dev):
             return (0,{},{})
 
-        devid = blkif.blkdev_name_to_number(sxp.child_value(config, 'dev'))
+        devid = blkif.blkdev_name_to_number(dev)
 
         (typ, params) = string.split(sxp.child_value(config, 'uname'), ':', 1)
-        back = { 'type' : typ,
+        back = { 'dev' : dev,
+                 'type' : typ,
                  'params' : params
                  }
 
@@ -57,3 +58,22 @@ class BlkifController(DevController):
         front = { 'virtual-device' : "%i" % devid }
 
         return (devid, back, front)
+
+
+    def configuration(self, devid):
+        """@see DevController.configuration"""
+
+        result = DevController.configuration(self, devid)
+
+        (dev, typ, params, ro) = self.readBackend(devid,
+                                                  'dev', 'type', 'params',
+                                                  'read-only')
+
+        result.append(['dev', dev])
+        result.append(['uname', typ + ":" + params])
+        if ro:
+            result.append(['mode', 'r'])
+        else:
+            result.append(['mode', 'w'])
+
+        return result
index 127529ad5612469d0fd25df185b4a84fa69fe5c1..d195363ba5fd7e2d88cb52960130377382e32305 100755 (executable)
 import os
 
 from xen.xend import sxp
+from xen.xend import XendRoot
 
 from xen.xend.server.DevController import DevController
 
 
+xroot = XendRoot.instance()
+
+
 class NetifController(DevController):
     """Network interface controller. Handles all network devices for a domain.
     """
@@ -38,9 +42,6 @@ class NetifController(DevController):
     def getDeviceDetails(self, config):
         """@see DevController.getDeviceDetails"""
 
-        from xen.xend import XendRoot
-        xroot = XendRoot.instance()
-
         def _get_config_ipaddr(config):
             val = []
             for ipaddr in sxp.children(config, elt='ip'):
@@ -68,3 +69,22 @@ class NetifController(DevController):
                   'mac' : mac }
 
         return (devid, back, front)
+
+
+    def configuration(self, devid):
+        """@see DevController.configuration"""
+
+        result = DevController.configuration(self, devid)
+
+        (script, ip, bridge, mac) = self.readBackend(devid,
+                                                     'script', 'ip', 'bridge',
+                                                     'mac')
+
+        result.append(['script',
+                       script.replace(xroot.network_script_dir + os.sep, "")])
+        if ip:
+            result.append(['ip', ip.split(" ")])
+        result.append(['bridge', bridge])
+        result.append(['mac', mac])
+
+        return result